﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CNFProblem.CNF
{
    /// <summary>
    /// Lista alternatyw literałów - razem tworzą ich koniunkcję, postać 3CNF
    /// </summary>
    public class LogicalFormula3CNF : List<LiteralAlternative>
    {
        private Variables _variables = new Variables();

        public Variables Variables
        {
            get { return _variables; }
            set { _variables = value; }
        }

        public bool GetValue(Dictionary<int, bool> values)
        {
            bool v = true;
            foreach (var item in this)
            {
                v &= item.GetValue(values);
                if (!v) break;
            }

            return v;
        }

        public List<List<VariableRepresentation>> GetVariableRepresentations()
        {
            List<List<VariableRepresentation>> result = new List<List<VariableRepresentation>>();
            foreach (LiteralAlternative item in this)
            {
                List<VariableRepresentation> literalAlt = new List<VariableRepresentation>();
                for (int i = 0; i < item.GetLenght(); ++i)
                {
                    literalAlt.Add(new VariableRepresentation(Variables.GetName(item.GetId(i)), item.GetNeg(i)));
                }
                result.Add(literalAlt);
            }
            return result;
        }
    }
}
